From 907e41d0a13fd4ac6aa192a61acd00f8143ad387 Mon Sep 17 00:00:00 2001 From: Jake Goldsborough Date: Wed, 5 Oct 2016 16:40:10 -0700 Subject: [PATCH] tweaking the way the dropdown opens to fix links not working --- src/doc/javascripts/all.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/doc/javascripts/all.js b/src/doc/javascripts/all.js index 2694e8fc6..d2124a952 100644 --- a/src/doc/javascripts/all.js +++ b/src/doc/javascripts/all.js @@ -19,18 +19,23 @@ $(function() { pres[i].className += ' language-rust'; } + // Toggles docs menu $('button.dropdown, a.dropdown').click(function(el, e) { - $(this).toggleClass('active'); - $(this).siblings('ul').toggleClass('open'); + $(this).toggleClass('active').siblings('ul').toggleClass('open'); - if ($(this).hasClass('active')) { - $(document).on('mousedown.useroptions', function() { - setTimeout(function() { - $('button.dropdown, a.dropdown').removeClass('active'); - $('button.dropdown + ul').removeClass('open'); - }, 150); - $(document).off('mousedown.useroptions'); - }); + return false; + }); + + // A click in the page anywhere but in the menu will turn the menu off + $(document).on('click', function(e) { + // Checks to make sure the click did not come from inside dropdown menu + // if it doesn't we close the menu + // else, we do nothing and just follow the link + if (!$(e.target).closest('ul.dropdown').length) { + var toggles = $('button.dropdown.active, a.dropdown.active'); + toggles.toggleClass('active').siblings('ul').toggleClass('open'); + + return false; } }); }); -- 2.30.2